/**
 * @param {number[]} nums1
 * @param {number[]} nums2
 * @return {number[]}
 */
var intersect = function (nums1, nums2) {
  let result = []
  for (let i = 0; i < nums1.length; i++) {
    for (let j = 0; j < nums2.length; j++) {
      if (nums1[i] == nums2[j]) {
        result.push(nums1[i]);
        nums2.splice(j, 1)
        j--
        break;
      }
    }
  }
  console.log(result)
  return result
};
let nums1 = [1, 2, 2, 1], nums2 = [2, 2]
intersect(nums1, nums2)